package com.ymatou.iapi.productprice.testcase;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.prodstock.parameter.PCatalogListDto;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.CatalogSaveModel;
import com.ymatou.iapi.productprice.parameter.GetBriefPriceByProdIdsBean;
import com.ymatou.iapi.productprice.parameter.ProductAllPriceBean;
import com.ymatou.iapi.productprice.service.GetBriefPriceByProdIdsCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.*;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
*获取商品价格简要列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetBriefPriceByProdIds{
	private static GetBriefPriceByProdIdsBean getbriefpricebyprodidsBean;
	private static GetBriefPriceByProdIdsCall getbriefpricebyprodidsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商品价格简要列表");
		try {
			GodfreightmgrService.deleteBySellerId(rootUserId);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		getbriefpricebyprodidsBean=new GetBriefPriceByProdIdsBean();
		getbriefpricebyprodidsCall=new GetBriefPriceByProdIdsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbriefpricebyprodidsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_001() {
		Logger.start(true,"获取商品价格简要列表成功,新客");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			Logger.comment("修改商品规格信息,设置新客价格最便宜");
			//场景描述1规格新客价格最便宜
			addpro.getProduct().getCatalogList().remove(1);
			CatalogSaveModel c = addpro.getProduct().getCatalogList().get(0);
			Double np=1.2d;
			c.setNewPrice(np);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setBuyerId(9999999);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(1, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(0d, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(np, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(c.getPrice(), pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(np, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(0d, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(c.getPrice(), pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_002() {
		Logger.start(false,"不输入ProductIds失败");
		try {
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("400", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_003() {
		Logger.start(true,"获取商品价格简要列表成功,VIP客户");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(1);
			CatalogSaveModel c = addpro.getProduct().getCatalogList().get(0);
			Double vp=1.2d;
			c.setVipPrice(vp);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			//查询vip用户
			//Ymt_BuyerOrders.BuyerSellerOrderStatistics sellerid查询 FirstPaidTime 跟当前日期比较，大于5天就是VIP客户
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			Integer buyerid=ProductManagerCallServiceV2.getVipUid(sellerId);
			getbriefpricebyprodidsBean.setBuyerId(buyerid);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();				
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(2, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(0d, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(vp, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(c.getPrice(), pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(vp, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(0d, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(c.getPrice(), pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_004() {
		Logger.start(true,"多规格获取商品价格简要列表成功,验证最高价最低价区别");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			Logger.comment("修改商品规格信息,设置新客价格最便宜");
			//场景描述1规格新客价格最便宜
			CatalogSaveModel c = addpro.getProduct().getCatalogList().get(0);
			Double np=1.2d;
			c.setNewPrice(np);
			CatalogSaveModel c2 = addpro.getProduct().getCatalogList().get(1);
			Double np2=2d;
			c2.setNewPrice(np2);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			List<Double> prices = addpro.getProduct().getCatalogList().stream().map(x -> x.getPrice()).collect(Collectors.toList());
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setBuyerId(9999999);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(1, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(0d, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(np2, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(Collections.max(prices), pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(np, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(0d, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(Collections.min(prices), pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_005() {
		Logger.start(true,"多物流获取商品价格简要列表成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			Logger.comment("修改多物流方式贝海多物流方式贝海");
			Integer mult=3;
			Double fbalance=1.50d;
			addpro.getProduct().setMultiLogistics(mult);//多物流方式贝海
			addpro.getProduct().setFlightBalance(fbalance);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				Logger.verifyEquals(mult, pp.getExtraDeliveryType(), "验证ExtraDeliveryTypeExtraDeliveryType");
				Logger.verifyEquals(fbalance, pp.getExtraDeliveryFee(), "验证ExtraDeliveryFee");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_006() {
		Logger.start(true,"非交易隔离活动获取商品价格简要列表成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			Logger.comment("修改商品规格信息,设置新客价格最便宜");
			//场景描述1规格新客价格最便宜
			addpro.getProduct().getCatalogList().remove(1);
			CatalogSaveModel c = addpro.getProduct().getCatalogList().get(0);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			
			Integer activityId = ActivityCallService.createNoIsolationActivityInProcess();
			Double ap=3.0d;
			//活动价格
			List<String> inaids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId, catalogs, activityId, 10,ap.toString() );
			ProductManagerCallServiceV2.approveProductInActivity(productId, inaids.get(0), true);
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setBuyerId(9999999);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(3, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(ap, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(ap, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(c.getPrice(), pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(ap, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(ap, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(c.getPrice(), pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_007() {
		Logger.start(true,"获取商品价格简要列表成功,不输入用户id");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().forEach(catalog->catalog.setPrice(20d));
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(1, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(0d, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(10d, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(20.0, pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(8.0, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(0d, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(20.0, pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_008() {
		Logger.start(true,"交易隔离活动获取商品价格简要列表成功,不显示活动价价格");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			Logger.comment("修改商品规格信息,设置新客价格最便宜");
			//场景描述1规格新客价格最便宜
			addpro.getProduct().getCatalogList().remove(1);
			CatalogSaveModel c = addpro.getProduct().getCatalogList().get(0);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			
			Integer activityId = ActivityCallService.createIsolationActivityInProcess();
			Double ap=3.0d;
			//活动价格
			List<String> inaids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId, catalogs, activityId, 10,ap.toString() );
			ProductManagerCallServiceV2.approveProductInActivity(productId, inaids.get(0), true);
			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setBuyerId(9999999);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();			
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(1, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(0d, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(c.getNewPrice(), pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(c.getPrice(), pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(c.getNewPrice(), pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(0d, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(c.getPrice(), pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_009() {
		Logger.start(true,"获取商品价格简要列表成功,新人活动，新哈尼,true");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndIsolation();
			List<Double> fQuotePriceList = productAllPriceBean.getCatalogAllPriceBeans().stream().map(x -> x.getfQuotePrice()).collect(Collectors.toList());
			List<Double> fActivityPriceList = productAllPriceBean.getCatalogAllPriceBeans().stream().map(x -> x.getfActivityPrice()).collect(Collectors.toList());

			Double maxPrice = Collections.max(fQuotePriceList);
			Double minPrice = Collections.min(fQuotePriceList);

			Double maxActPrice = Collections.max(fActivityPriceList);
			Double minActPrice = Collections.min(fActivityPriceList);
			String productId = productAllPriceBean.getProductId();

			UserRegisterInfoRequestDtoBean regbean	= JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();

			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setBuyerId(userId);
			getbriefpricebyprodidsBean.setTradeIsolation(true);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(3, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(maxActPrice, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(maxActPrice, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(maxPrice, pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(minActPrice, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(minActPrice, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(minPrice, pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBriefPriceByProdIds_010() {
		Logger.start(true,"获取商品价格简要列表成功,新人活动，新哈尼,false");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndIsolation();
			List<Double> fQuotePriceList = productAllPriceBean.getCatalogAllPriceBeans().stream().map(x -> x.getfQuotePrice()).collect(Collectors.toList());
			List<Double> fActivityPriceList = productAllPriceBean.getCatalogAllPriceBeans().stream().map(x -> x.getfActivityPrice()).collect(Collectors.toList());
			List<Double> newPriceList = productAllPriceBean.getCatalogAllPriceBeans().stream().map(x -> x.getfNewCustomerPrice()).collect(Collectors.toList());

			Double maxPrice = Collections.max(fQuotePriceList);
			Double minPrice = Collections.min(fQuotePriceList);

			Double maxActPrice = Collections.max(fActivityPriceList);
			Double minActPrice = Collections.min(fActivityPriceList);

			Double newMaxActPrice = Collections.max(newPriceList);
			Double newMinPrice = Collections.min(newPriceList);
			String productId = productAllPriceBean.getProductId();

			UserRegisterInfoRequestDtoBean regbean	= JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();

			Thread.sleep(2000);
			List<String> ProductIds=new ArrayList<String>();
			ProductIds.add(productId);
			getbriefpricebyprodidsBean.setBuyerId(userId);
			getbriefpricebyprodidsBean.setProductIds(ProductIds);
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("Code"), "验证Code");
			Logger.verifyEquals("200", getbriefpricebyprodidsCall.getString("BCode"), "验证BCode");
			getbriefpricebyprodidsCall.getProductPriceList().forEach(pp->{
				//0 - 原价，1 - 直播新客价，2 - 直播VIP价，3 - 码头活动价
				Logger.verifyEquals(1, pp.getPriceType(), "验证PriceType");
				//没有活动时候为0
				Logger.verifyEquals(0d, pp.getMaxActivityPrice(), "验证MaxActivityPrice用户可以享受的最高活动价");
				Logger.verifyEquals(newMaxActPrice, pp.getMaxPrice(), "验证MaxPrice用户可以享受的最高价");
				Logger.verifyEquals(maxPrice, pp.getMaxQuotePrice(), "验证MaxQuotePrice用户可以享受的最高原价");
				Logger.verifyEquals(newMinPrice, pp.getMinPrice(), "验证MinPrice用户可以享受的非零最低价");
				Logger.verifyEquals(0d, pp.getMinActivityPrice(), "验证MinActivityPrice用户可以享受的非零最低活动价");
				Logger.verifyEquals(minPrice, pp.getMinQuotePrice(), "验证MinQuotePrice用户可以享受的非零最低原价");
				Logger.verifyEquals(productId, pp.getProductId(), "验证productId");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}



	/////////////////////////   忽略case /////////////////////////////
	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_GetBriefPriceByProdIds_011() {
		Logger.start(true, "查询限时抢八折后价格");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			double price = 123.6;
			addAgentProductBean.getCatalogList().forEach(a -> {
				a.getAgentPriceList().forEach(b -> {
					b.setAgentPrice(price);
				});
				a.setDirectPrice(price);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			// 创建限时抢购活动
			List<String> catalogList = new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,
					productId);
			selectProductDetails.getCatalogList().forEach(a -> {
				catalogList.add(a.getCatalogId());
			});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId,
					productId, catalogList);
			initProductaddactivity.getProductList().forEach(a -> {
				a.getCatalogList().forEach(b -> {
					b.setDiscount(new BigDecimal("8"));
				});
			});
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
			Thread.sleep(4000);
			getbriefpricebyprodidsBean.setBuyerId(rootUserId);
			getbriefpricebyprodidsBean.setProductIds(Arrays.asList(productId));
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();
			JsonObject jsonObject = getbriefpricebyprodidsCall.getJsonObject();
			JsonObject asJsonObject = jsonObject.getAsJsonObject("Data").getAsJsonArray("ProductPriceList").get(0)
					.getAsJsonObject();

			Logger.verifyEquals(price * 0.8, asJsonObject.get("MinPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price * 0.8, asJsonObject.get("MaxPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price * 0.8, asJsonObject.get("MinActivityPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price * 0.8, asJsonObject.get("MaxActivityPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price, asJsonObject.get("MinQuotePrice").getAsDouble(), "验证是否为原价");
			Logger.verifyEquals(price, asJsonObject.get("MaxQuotePrice").getAsDouble(), "验证是否为原价");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_GetBriefPriceByProdIds_012() {
		Logger.start(true, "查询限时抢八折后价格  库存扣完之后，活动价格0.0");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			double price = 123.6;
			addAgentProductBean.getCatalogList().forEach(a -> {
				a.setStock(1000);
				a.getAgentPriceList().forEach(b -> {
					
					b.setAgentPrice(price);
				});
				a.setDirectPrice(price);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			// 创建限时抢购活动
			List<String> catalogList = new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,
					productId);
			selectProductDetails.getCatalogList().forEach(a -> {
				catalogList.add(a.getCatalogId());
			});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId,
					productId, catalogList);
			initProductaddactivity.getProductList().forEach(a -> {
				a.getCatalogList().forEach(b -> {
					b.setDiscount(new BigDecimal("8"));
				});
			});
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
			Thread.sleep(4000);
			getbriefpricebyprodidsBean.setBuyerId(rootUserId);
			getbriefpricebyprodidsBean.setProductIds(Arrays.asList(productId));
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();
			JsonObject jsonObject = getbriefpricebyprodidsCall.getJsonObject();
			JsonObject asJsonObject = jsonObject.getAsJsonObject("Data").getAsJsonArray("ProductPriceList").get(0)
					.getAsJsonObject();

			Logger.verifyEquals(price * 0.8, asJsonObject.get("MinPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price * 0.8, asJsonObject.get("MaxPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price * 0.8, asJsonObject.get("MinActivityPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price * 0.8, asJsonObject.get("MaxActivityPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price, asJsonObject.get("MinQuotePrice").getAsDouble(), "验证是否为原价");
			Logger.verifyEquals(price, asJsonObject.get("MaxQuotePrice").getAsDouble(), "验证是否为原价");

			
			Thread.sleep(4000);
			
			//减去所有库存
			int reduceNum =1000;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(0), rootUserId, activityId, reduceNum, 0, true);
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(1), rootUserId, activityId, reduceNum, 0, true);
			
			
			Thread.sleep(4000);
			getbriefpricebyprodidsBean.setBuyerId(rootUserId);
			getbriefpricebyprodidsBean.setProductIds(Arrays.asList(productId));
			getbriefpricebyprodidsCall.setData(getbriefpricebyprodidsBean);
			getbriefpricebyprodidsCall.callService();
			jsonObject = getbriefpricebyprodidsCall.getJsonObject();
			asJsonObject = jsonObject.getAsJsonObject("Data").getAsJsonArray("ProductPriceList").get(0)
					.getAsJsonObject();

			Logger.verifyEquals(price, asJsonObject.get("MinPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price, asJsonObject.get("MaxPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(0.0, asJsonObject.get("MinActivityPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(0.0, asJsonObject.get("MaxActivityPrice").getAsDouble(), "验证是否为八折价格");
			Logger.verifyEquals(price, asJsonObject.get("MinQuotePrice").getAsDouble(), "验证是否为原价");
			Logger.verifyEquals(price, asJsonObject.get("MaxQuotePrice").getAsDouble(), "验证是否为原价");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}